package com.ping.study.controller.tx;

import com.ping.study.service.tx.LiveInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/tx/nba")
@Slf4j
public class LiveInfoController {

    private final LiveInfoService liveInfoService;

    public LiveInfoController(LiveInfoService liveInfoService) {
        this.liveInfoService = liveInfoService;
    }

    @GetMapping("/live/{cnlid}")
    public String getLiveInfo(@PathVariable String cnlid) throws Exception {
        log.info("执行查询直播cnlid: {}", cnlid);
        return liveInfoService.getLiveInfo(cnlid);
    }

    //定时执行更新直播链接
    //定时任务 从北京时间凌晨到12点，每过半个小时执行一次
    @Scheduled(cron = "0 0/15 0-12 * * ?")
    @RequestMapping("/live/refresh")
    public String refreshLiveInfo() throws Exception {
        log.info("=========开始执行更新直播链接=========");
        return liveInfoService.refreshLiveInfo();
    }
}
